using UnityEngine;
using UnityEngine.UI;

public class DiePanel : BasePanel
{
    [Header("继续按钮")]
    public Button continueButton;

    public override void OnClose()
    {
        base.OnClose();
    }

    public override void OnInit()
    {
        base.OnInit();

        path="UI/Panel/DiePanel";
        type=PanelType.Panel;

        GameManager.Instance.canOprate=false;
    }

    public override void OnShow(params object[] par)
    {
        base.OnShow(par);

        continueButton=item.transform.Find("Re").GetComponent<Button>();

        continueButton.onClick.AddListener(ContinueButton);
    }

    //继续按钮
    public void ContinueButton()
    {
        //加载原数据
        SceneItemManager.instance.LoadData();
        //死亡数据
        SaveManager.instance.DieLoadData();
        PanelManager.Open<BlackPanel>(true, true,SceneItemManager.instance.id, false,0);
        //更新UI数据
        GameManager.Instance.UpdateMathData();
        //死亡惩罚
        DiePunishment();
        //设置死亡
        //玩家死亡变成幽灵
        Player player = GameManager.Instance.player;
        GameManager.Instance.PlayerDie(new Vector2(player.transform.position.x, player.transform.position.y)
            , SceneItemManager.instance.id);

        Close();

        AudManager.instance.PlayUIAud(AudManager.instance.uiDic["点击"], 1);
    }
    //处理死亡惩罚
    public void DiePunishment()
    {
        if(GameManager.Instance.eatBloodFruit)
        {
            GameManager.Instance.eatBloodFruit=false;
            return;
        }

        Player player = GameManager.Instance.player;
        //血量减少30%，最低为1
        int reNum = Mathf.RoundToInt(player.currHp*0.3f);
        if (player.currHp-reNum<=1) reNum = player.currHp - 1;
        player.ReHp(reNum);
    }
}
